package com.tfjybj.itoo.exam.provider.service.impl;

import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Reference;;
import com.dmsdbj.itoo.tool.constantutil.YearSemester;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.provider.service.TrainingProgramsService;
import com.tfjybj.itoo.teach.FacadeApi.CourseApi;
import com.tfjybj.itoo.teach.FacadeApi.TrainingProgramsApi;
import com.tfjybj.itoo.teach.entity.CourseEntity;
import com.tfjybj.itoo.teach.entity.TrainingProgramsEntity;
import com.tfjybj.itoo.teach.model.TrainingProgramsModel;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * TrainingProgramsService接口实现类
 * ${base}表
 *
 * @author 杨江涛
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 10:35:56
 */
@Service("trainingProgramsService")
public class TrainingProgramsServiceImpl  implements TrainingProgramsService {
	
	//region 模板生成

    @DubboReference(check = false)
    private TrainingProgramsApi trainingProgramsApi;

    @DubboReference(check = false)
    private CourseApi courseApi;

    @Override
    public PageInfo<TrainingProgramsEntity> queryByLikeCourseId(String courseId, Integer pageNum, Integer pageSize) {
        return trainingProgramsApi.queryByCourseId(courseId, pageNum, pageSize);
    }

    //endregion

    /* **********************************以下为非模板生成的内容********************************* */


    @Override
    public List<TrainingProgramsEntity> findCourseId() {
        //从工具类中获取当前学年的ID
        String semester= YearSemester.getYearSemesterCode(0,0).get(0);

        TrainingProgramsEntity trainingProgramsEntity=new TrainingProgramsEntity();
        trainingProgramsEntity.setSemesterId(semester);
        return trainingProgramsApi.findCourseId();
    }


    @Override
    public List<TrainingProgramsModel> findByProfessionId(String professionId) {
        List<TrainingProgramsModel> trainList=new ArrayList<>();
        List<TrainingProgramsEntity> trainingProgramsEntityList= findCourseId();
        List<CourseEntity> courseEntityList=new ArrayList<>();
        //TODO
        for (TrainingProgramsEntity courseId:trainingProgramsEntityList) {
            courseEntityList.add(courseApi.getById(courseId.getCourseId()));
        }
        for (CourseEntity courseName:courseEntityList) {
            TrainingProgramsModel traModel=new TrainingProgramsModel();
            traModel.setCourseName(courseName.getName());
            traModel.setCourseCategoryId(courseName.getCourseCategory());
            traModel.setCourseTypeId(courseName.getCourseType());
            traModel.setCourseCode(courseName.getCode());
            traModel.setCourseId(courseName.getId());

            trainList.add(traModel);
        }
        return trainList;
    }

    @Override
    public List<TrainingProgramsModel> findCourseByProfessionId(String professionId) {
        //从工具类中获取当前学年的ID
//        String semester= YearSemester.getYearSemesterCode(0,0).get(0);

        return trainingProgramsApi.findCourseByProfessionId(professionId);
    }
}
